import type { PageParam, PageResult } from '@vben/request';

import { requestClient } from '#/api/request';

export namespace CmtCourseLearnRecordApi {
  /** 课程学习记录 */
  export interface CourseLearnRecord {
    id?: number;
    userId?: number; // 用户ID
    courseId?: number; // 课程ID
    chapterId?: number; // 章节ID
    learnProgress?: number; // 学习进度(百分比)
    learnDuration?: number; // 学习时长(秒)
    isComplete?: number; // 是否完成：0否 1是
    completeTime?: string; // 完成时间
    createTime?: string; // 创建时间
    updateTime?: string; // 更新时间
  }

  /** 课程学习记录分页查询参数 */
  export interface CourseLearnRecordPageReqVO {
    pageNo: number;
    pageSize: number;
    userId?: number;
    courseId?: number;
    chapterId?: number;
    isComplete?: number;
    createTime?: string[];
  }
}

/** 查询课程学习记录分页 */
export function getCourseLearnRecordPage(params: CmtCourseLearnRecordApi.CourseLearnRecordPageReqVO) {
  return requestClient.get<PageResult<CmtCourseLearnRecordApi.CourseLearnRecord>>(
    '/cmt/course-learn-record/page',
    { params },
  );
}

/** 查询课程学习记录详情 */
export function getCourseLearnRecord(id: number) {
  return requestClient.get<CmtCourseLearnRecordApi.CourseLearnRecord>(
    `/cmt/course-learn-record/get?id=${id}`,
  );
}

/** 新增课程学习记录 */
export function createCourseLearnRecord(data: CmtCourseLearnRecordApi.CourseLearnRecord) {
  return requestClient.post('/cmt/course-learn-record/create', data);
}

/** 修改课程学习记录 */
export function updateCourseLearnRecord(data: CmtCourseLearnRecordApi.CourseLearnRecord) {
  return requestClient.put('/cmt/course-learn-record/update', data);
}

/** 删除课程学习记录 */
export function deleteCourseLearnRecord(id: number) {
  return requestClient.delete(`/cmt/course-learn-record/delete?id=${id}`);
}

/** 批量删除课程学习记录 */
export function deleteCourseLearnRecordList(ids: number[]) {
  return requestClient.delete(`/cmt/course-learn-record/delete-list?ids=${ids.join(',')}`);
}

/** 导出课程学习记录 */
export function exportCourseLearnRecord(params: CmtCourseLearnRecordApi.CourseLearnRecordPageReqVO) {
  return requestClient.download('/cmt/course-learn-record/export-excel', { params });
}
